<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>js练习d倒计时页面</title>
    <style>
        h1{
        display: block;
        text-align: center;
        margin: 30px auto;
        }
        div{
            margin: 15px 50%;
            height:40px;
            width:280px;
            position: relative;
            left:-140px;
        }
        #num{
            font-size: 50px;
            color: rgb(232, 16, 16);
        }
    </style>
  </head>
  <body>
    <h1>恭喜您，支付成功！</h1>
    <div>
        <span id="num">10</span>
        <span>秒后自动返回</span>
    </div>

    <br>
    <div>
        <button id="btn">立即返回</button>
    </div>
    <script>
        window.onload = function(){
            let timer = 10;
            setInterval(()=>{
                timer--;
                document.getElementById("num").innerHTML = timer;
                if(timer==0){
                    location.href = "./index.html";
                }
            },1000)
            document.getElementById("btn").onclick =  function() {
                    location.href = "./index.html";
                }
            }
    

    </script>
  </body>
</html>